Total Complexity | 2 |
Total Lines | 30 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import { |
||
18 | |||
19 | @Controller('quotes') |
||
20 | @ApiUseTags('Billing') |
||
21 | @ApiBearerAuth() |
||
22 | @UseGuards(AuthGuard('bearer')) |
||
23 | export class CreateQuoteAction { |
||
24 | constructor( |
||
25 | @Inject('ICommandBus') |
||
26 | private readonly commandBus: ICommandBus, |
||
27 | @Inject('IQueryBus') |
||
28 | private readonly queryBus: IQueryBus |
||
29 | ) {} |
||
30 | |||
31 | @Post() |
||
32 | @ApiOperation({title: 'Create new quote'}) |
||
33 | public async index( |
||
34 | @Body() quoteDTO: CreateQuoteDTO, |
||
35 | @LoggedUser() user: User |
||
36 | ) { |
||
37 | try { |
||
38 | const {projectId, customerId, status, items} = quoteDTO; |
||
39 | const id = await this.commandBus.execute( |
||
40 | new CreateQuoteCommand(user, status, customerId, projectId) |
||
41 | ); |
||
42 | |||
43 | await this.commandBus.execute(new CreateQuoteItemsCommand(id, items)); |
||
44 | |||
45 | return id; |
||
46 | } catch (e) { |
||
47 | throw new BadRequestException(e.message); |
||
48 | } |
||
51 |